<template>
    <div>
        <el-collapse v-model="activeNames">
            <el-collapse-item title="托盘AO查询" name="1">
                <!--查询-->
                <el-form :inline="true" :model="formInline" class="demo-form-inline">
                    <el-form-item label="托盘号">
                        <el-input v-model="formInline.palletCode"  size="mini" placeholder="托盘号"></el-input>
                    </el-form-item>
                    <el-form-item label="AO号">
                        <el-input v-model="formInline.aoCode"  size="mini" placeholder="AO号"></el-input>
                    </el-form-item>
                    <el-form-item label="工作包号">
                        <el-input v-model="formInline.packageCode"  size="mini" placeholder="工作包号"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary"  size="mini" @click="doQuery">查询</el-button>
                        <el-button type="primary" size="mini" @click="doReset">重置</el-button>
                        <el-button type="primary" size="mini" @click="exeTask">执行任务</el-button>
                    </el-form-item>
                </el-form>
                <!--托盘列表-->
                <el-table :data="tableData" height="200" border highlight-current-row @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="55"></el-table-column>
                    <el-table-column prop="msTaskPackageId" label="工作包ID" v-if="false"></el-table-column>
                    <el-table-column prop="palletCode" label="托盘" width="180"></el-table-column>
                    <el-table-column prop="packageCode" label="工作包编号" width="180"></el-table-column>
                    <el-table-column prop="planeNo" label="当前分拣批次" width="140"></el-table-column>
                    <el-table-column prop="palletStatusName" label="托盘状态" width="180" show-overflow-tooltip></el-table-column>
                    <el-table-column prop="aoCode" label="AO编号" show-overflow-tooltip></el-table-column>
                    
                </el-table>
                <!--分页参数-->
                <el-pagination @size-change="handleSizeChange"  @current-change="handleCurrentChange" :current-page="page.currentPage" 
                        :page-sizes="[50,100, 200, 300, 400]" :page-size="page.pageSize" layout="total, sizes, prev, pager, next" :total="page.total">
                </el-pagination>
            </el-collapse-item>
        </el-collapse>
    </div>
</template>
<script>
import request from "@/utils/request.js";
export default {
    inject:['reload'],
    data(){
        return{
            activeNames:['1'],
            formInline:{palletCode:"",aoCode:"",packageCode:""},
            page:{currentPage:1,total:0,pageSize:20},
            tableData:[],
            selectData:[]

        }
    },
    methods:{
         //查询
         doQuery(){
            var that = this;
            request.post("/PointPackageSortRest/searchPointPallet",{"page":this.page,"queryParam":this.formInline}).then((res)=>{
               // that.tableData = res.xxxxx
                that.page.total = res.data.total;
                that.tableData = res.data.list;
            });
        },
        doReset(){//重置
            Object.assign(this.formInline,this.$options.data().formInline);
        },
        handleSizeChange(val){
            this.page.pageSize=val;
            this.$options.methods.doQuery.bind(this)();
        },
        handleCurrentChange(val){
            this.page.currentPage=val;
            this.$options.methods.doQuery.bind(this)();
        },
        handleSelectionChange(val){
            this.selectData = val;
        },
        exeTask(){
           /* if(this.selectData.length==1){
                this.$Alert({type:"error",message:"请选择一条记录",title:"错误"});
                return ;
            }*/
            this.$prompt('请输入分拣的架次', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消'
            }).then(({ value }) => {
                var planeNo = value;
                var palletCode = "";
                for(var i = 0;i<this.selectData.length;i++){
                    if(palletCode==""){
                        palletCode = this.selectData[i].palletCode;
                    }else if(palletCode!=this.selectData[i].palletCode){
                        this.$Alert({type:"error",message:"请选择相同托盘的工作包!",title:"错误"});
                        return ;
                    }
                }
                var param = {datas:this.selectData,palletCode:palletCode,planeNo:planeNo}
                request.post("/PointPackageSortRest/startPalletSort",param).then((res=>{
                    if(res.data.retCode=="1"){
                        this.$Alert({type:"success",message:res.data.retMsg,title:"成功"});
                    }else{
                        this.$Alert({type:"error",message:res.data.retMsg,title:"错误"});
                    }
                }));
            }).catch(() => {});

           

        }
    }
}
</script>